/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.web.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.losenote.model.OperateContext;
import com.losenote.service.MessageService;
import com.losenote.service.result.LnResult;
import com.losenote.web.ct.MessageCt;
import com.losenote.web.form.MessageForm;

/**
 * 消息控制器 
 * 
 * @author danjingyu
 * @version $Id: MessageController.java, v 0.1 2013-12-1 下午12:58:31 danjingyu Exp $
 */
@Controller
public class MessageController extends BaseController {
    /**消息服务*/
    @Autowired
    private MessageService messageService;

    /**
     * 处理请求
     * 
     * @param request
     * @param messageForm
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "replyMessage.json", produces = "text/plain;charset=UTF-8")
    @ResponseBody
    public Object handleRequest(HttpServletRequest request, MessageForm messageForm)
                                                                                    throws Exception {
        OperateContext context = getOperateContext(request);
        LnResult lnResult = messageService.saveMessage(MessageCt.fromForm(messageForm, context),
            context);
        return lnResult;
    }

    public void setMessageService(MessageService messageService) {
        this.messageService = messageService;
    }

}
